package org.micservice.contorller;


import org.micservice.ResultMap;
import org.micservice.User;
import org.micservice.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("customer")
public class CustomerController {


    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("getUsers")
    public ResultMap getUsers() {
        return restTemplate.getForObject("http://provider/provider/getUsers", ResultMap.class);
    }

    @Autowired
    CustomerService customerService;

    @RequestMapping("getUsersFeign")
    public ResultMap getUsersFeign() {
        return customerService.getUsers();
    }

    @PostMapping("addUserFeign")
    public ResultMap addUserFeign(@RequestBody User user) {
        return customerService.addUser(user);
    }

}
